package gui;

import java.io.File;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;

import gamemngr.GameMngr;

public class SaveData {
	
	private String saveName;
	private boolean saved;
	private GameMngr game;
	private Shell shell;
	
	public SaveData(GameMngr game, Shell shell){
		this.saved = false;
		this.game = game;
		this.shell = shell;
	}
	
	public void saveGame(){
		boolean newSave = true;
		if(saved){
			MessageDialog msg = new MessageDialog(shell,"Overwrite",null,"Do you want to replace the previously saved game?",MessageDialog.QUESTION,new String[] {"Yes","No"},1);
			if(msg.open() == 0){
				game.saveGame(new File(this.saveName));
				AutoDialogMessegaes.displayFeedbackMsg("Success", "Saved!", shell);
				newSave = false;
			}
		}
		if(newSave){
			SaveDialog save = new SaveDialog(shell, game, this);
			save.open();
		}
		this.saved = true;
	}

	/**
	 * @param saveName the saveName to set
	 */
	public void setSaveName(String saveName) {
		this.saveName = saveName;
	}
	
	/**
	 * @param saved the saved to set
	 */
	public void setSaved(boolean saved) {
		this.saved = saved;
	}
}
